<?php
session_start();

$prefix_url = "/";
global $lg;
$lg = $_SESSION['lg'];
if($lg=="en")
	$prefix_url = "/en/";
	
header("Content-Type: text/html; charset=utf-8"); 
define('CLASS_DIR','../class/');
include('../includes/config.php');
include('../includes/functions.php');

global $db;

$cid = $_GET['cid'];

if(!is_numeric($cid))
	die("don't hack me :D");

global $set_per_page, $page, $sqlstmt, $c;
$set_per_page=8; 
$page   = isset($_GET["page"])  ? $_GET["page"]  : '1';
$sql="select p.* from products p where p.active=1 and p.cid=".$_GET['cid']." order by p.num asc, p.id desc ";
$c = $db->numRows($db->query($sql));
$sqlstmt = sqlmod($sql,$page,$set_per_page);	
$products = $db->getAll($sqlstmt);

$result = $db->query($sql);
$rows = $db->numRows($result);
$p=ceil($rows/$set_per_page);

if($products){ 
?>

<div class="wrapper_products" id="relative_products">
	<?php
	global $cat1,$cat2, $lg, $prefix_url;
	$n = count($products);
	for($i=0; $i<$n; $i++){
		$product = $products[$i];
		$product_id = $product['id'];
		//$link = GetProductLink2($product, $lg);
		$link = "Javascript:GetProductDetail($product_id);";
?>
	<div class="item <?php echo $i%4==0?' first':''; ?>">
		<p><a href="<?=$link?>" title="<?php echo $product['name_'.$_SESSION['lg']]; ?>"><img src="/<?php echo $product['img']; ?>" alt="g1" /></a></p>
		<p class="name"><a href="<?=$link?>"><?php echo $product['name_'.$_SESSION['lg']]; ?></a></p>
	</div>
	<?php } ?>
	<?php if($p>1){ ?>
	<div class="cl"></div>
	<div class="Paging">
		<ul>
		<?php 
			for($i=1; $i<=$p; $i++){ 
				if($i==$page){
		?>
			<li<?php echo $i==1?' class="First"':''; ?>><a class="Active" href="#"><?php echo $i; ?></a></li>
		<?php }else{ ?>
			<li<?php echo $i==1?' class="First"':''; ?>><a href="Javascript:GetProducts(<?php echo $cid; ?>, <?php echo $i; ?>);"><?php echo $i; ?></a></li>
		<?php }	} ?>
		</ul>
	</div>
	<?php } ?>
</div>
<?php	}	?>
